<%@page import="com.liferay.portal.util.PortalUtil"%>
<%@page import="com.liferay.portal.kernel.dao.orm.PropertyFactoryUtil"%>
<%@page import="com.liferay.portal.kernel.dao.orm.OrderFactoryUtil"%>
<%@page import="com.liferay.portal.kernel.dao.orm.DynamicQuery"%>
<%@page import="com.liferay.portlet.ratings.model.RatingsEntry"%>
<%@page import="com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil"%>
<%@page import="com.liferay.portlet.ratings.service.RatingsEntryLocalServiceUtil"%>
<%@ include file="/jsps/init.jsp"%>
<%
	int detal = 10;
	UserSongs searchUserSongs = UserSongsLocalServiceUtil.createUserSongs(0);
%>

<ul class="song-list">
<liferay-ui:search-container emptyResultsMessage="no-song-found">
	<c:if test="<%= !\"rating\".equals(orderByCol) %>">
		<liferay-ui:search-container-results>
			<%
			results = UserSongsServiceUtil.search(searchUserSongs, searchContainer.getStart(), searchContainer.getEnd(), orderByCol, orderByType);
			results = ListUtil.copy(results);
			total = UserSongsServiceUtil.searchCount(searchUserSongs);
			
			pageContext.setAttribute("results", results);
			pageContext.setAttribute("total", total);
			%>
		</liferay-ui:search-container-results>
		
		<liferay-ui:search-container-row className="com.mto.module.karaoke.model.UserSongs" modelVar="userSongs" keyProperty="userSongId">
			<%
			Song song = SongLocalServiceUtil.getSong(userSongs.getSongId());
			User songUser = UserLocalServiceUtil.getUser(userSongs.getUserId()); 
			%>
			<li class="<%= index%2==0?"even-row":"odd-row"%>">
				<c:out value="<%=song.getSongName() %>"></c:out> [<c:out value="<%=songUser.getScreenName() %>"></c:out>]
			</li>
		</liferay-ui:search-container-row>
	</c:if>
	
	<c:if test="<%= \"rating\".equals(orderByCol) %>">
		<liferay-ui:search-container-results>
			<%
			long classNameId = PortalUtil.getClassNameId(UserSongs.class);
			DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(RatingsEntry.class);
			dynamicQuery.addOrder(OrderFactoryUtil.desc("score"));
			dynamicQuery.add(PropertyFactoryUtil.forName("classNameId").eq(classNameId));
			results = RatingsEntryLocalServiceUtil.dynamicQuery(dynamicQuery, searchContainer.getStart(), searchContainer.getEnd());
			total = (int)RatingsEntryLocalServiceUtil.dynamicQueryCount(dynamicQuery);
			pageContext.setAttribute("results", results);
			pageContext.setAttribute("total", total);
			%>
		</liferay-ui:search-container-results>
		
		<liferay-ui:search-container-row className="com.liferay.portlet.ratings.model.RatingsEntry" modelVar="ratingsEntry" keyProperty="entryId">
			<%
			long userSongId = ratingsEntry.getClassPK();
			UserSongs userSongs = UserSongsLocalServiceUtil.getUserSongs(userSongId);
			Song song = SongLocalServiceUtil.getSong(userSongs.getSongId());
			User songUser = UserLocalServiceUtil.getUser(userSongs.getUserId()); 
			%>
			<li class="<%= index%2==0?"even-row":"odd-row"%>">
				<c:out value="<%=song.getSongName() %>"></c:out> [<c:out value="<%=songUser.getScreenName() %>"></c:out>]
			</li>
		</liferay-ui:search-container-row>
	</c:if>
</liferay-ui:search-container>
</ul>